package com.syq.controller;

import com.syq.annotation.RequiresPermissionsDesc;
import com.syq.pojo.DtsCategory;
import com.syq.service.DtsCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @ClassName: AdminCategoryController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/28 10:27
 */

@RestController
@RequestMapping("/admin/category")
@CrossOrigin
public class AdminCategoryController {

    @Autowired
    private DtsCategoryService dtsCategoryService;


    @RequiresPermissionsDesc(menu = {"商场管理","类目管理"},button = "查询")
    @RequiresPermissions(value = "admin:category:list")
    @GetMapping("/list")
    public Object list(@RequestParam(defaultValue = "1")Integer page,
                       @RequestParam(defaultValue = "10")Integer limit,
                       @RequestParam(defaultValue = "add_time")String sort,
                       @RequestParam(defaultValue = "desc")String order,String name,Integer id){
        return dtsCategoryService.findAll(page,limit,sort,order,name,id);
    }


    @GetMapping("/l1")
    public Object l1(){
        return dtsCategoryService.findL1();
    }

    @RequiresPermissionsDesc(menu = {"商场管理","类目管理"},button = "添加")
    @RequiresPermissions(value = "admin:category:create")
    @PostMapping("/create")
    public Object create(@RequestBody DtsCategory category){
        return dtsCategoryService.add(category);
    }

    @RequiresPermissionsDesc(menu = {"商场管理","类目管理"},button = "修改")
    @RequiresPermissions(value = "admin:category:update")
    @PostMapping("/update")
    public Object update(@RequestBody DtsCategory category){
        return dtsCategoryService.update(category);
    }

    @RequiresPermissionsDesc(menu = {"商场管理","类目管理"},button = "删除")
    @RequiresPermissions(value = "admin:category:delete")
    @PostMapping("/delete")
    public Object delete(@RequestBody DtsCategory category){
        return dtsCategoryService.delete(category);
    }

}
